<script type="text/javascript" src="../js/common.js"> </script>
<script >
	function addElement() {

	  var ni = document.getElementById('myDiv');

	  var numi = document.getElementById('theValue');

	  var num = (document.getElementById('theValue').value -1)+ 2;

	  numi.value = num;

	  var newdiv = document.createElement('div');

	  var divIdName = 'my'+num+'Div';

	  newdiv.setAttribute('id',divIdName);
	  newdiv.setAttribute('style','float:left; width:100%');

	  newdiv.innerHTML = '<p><input type="hidden" id="userfile'+num+'" name="sanpham_hinhanh'+num+'" value=""/><img src="" width="50" id="imgdef'+num+'" name="imgdef'+num+'" height="40" style="float:left; border:#CCC 1px solid" /><input type="button" name="button3" value="Up file đính kèm" onclick="JavaScript:window.open(\'core/Upfile.php?Dir=content&amp;form=userfile'+num+'&img=imgdef'+num+'\',\'_upLoad\' ,\'height=220,width=450,resizable=no,scrollbars=yes\')") />&nbsp; <a href="javascript:;" onclick="removeElement(\''+divIdName+'\');">Xóa</a></p>';

	  ni.appendChild(newdiv);

	}
	function removeElement(divNum) {

	  var vl = document.getElementById('theValue');
	  vl.value= vl.value-1;
	  var d = document.getElementById('myDiv');

	  var olddiv = document.getElementById(divNum);

	  d.removeChild(olddiv);

	}
</script>
<script type="text/javascript" src="../tinymce/jscripts/tiny_mce/tiny_mce.js"></script>

					 <script type="text/javascript">						
						tinyMCE.init({
							entity_encoding : "raw",
							mode : "exact",
							elements : "txtnoidung",
							theme : "advanced",
							width : "850",
							height : "300", 
							plugins : "autolink,lists,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount,advlist,autosave,",

						
							theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,fontselect,fontsizeselect,undo,redo,|,link,unlink,image,forecolor,backcolor,pasteword",
							theme_advanced_buttons2 : "",
							theme_advanced_buttons3 : "",
							theme_advanced_buttons4 : "",
							theme_advanced_toolbar_location : "top",
							theme_advanced_toolbar_align : "left",							
							theme_advanced_resizing : false,

							
							content_css : "css/content.css",

							
							template_external_list_url : "lists/template_list.js",
							external_link_list_url : "lists/link_list.js",
							external_image_list_url : "lists/image_list.js",
							media_external_list_url : "lists/media_list.js",

							
							style_formats : [
								{title : 'Bold text', inline : 'b'},
								{title : 'Red text', inline : 'span', styles : {color : '#ff0000'}},
								{title : 'Red header', block : 'h1', styles : {color : '#ff0000'}},
								{title : 'Example 1', inline : 'span', classes : 'example1'},
								{title : 'Example 2', inline : 'span', classes : 'example2'},
								{title : 'Table styles'},
								{title : 'Table row 1', selector : 'tr', classes : 'tablerow1'}
							],

							
							template_replace_values : {
								username : "Some User",
								staffid : "991234"
							}
						});
</script>


<script language="javascript">
function validate_form(thisform)
{
with (thisform)
{
		if (validate_required(txtHoten,"Bạn chưa nhập tên cơ hội !")==false)
			{txtHoten.focus();return false;}

		if (validate_required(khachhang,"Bạn chưa chọn khách hàng!")==false)
			{khachhang.focus();return false;}
		if (validate_required(donviquanly,"Bạn chưa chọn đơn vị quản lý!")==false)
			{donviquanly.focus();return false;}
		if (validate_required(txtNguoiquanly,"Bạn chưa chọn người quản lý!")==false)
			{txtNguoiquanly.focus();return false;}
	
}
}
</script>

<!-- overlay -->
<div id="global">
	<div id="overlay" onclick="parent_disable();">		
	</div>
</div>
<!-- end overlay -->
<form style="padding:0; margin:0" action="index.php?tn=customers&kh=cohoi_xl" method="post" onsubmit="return validate_form(this);" name="frmAddMessage" enctype="multipart/form-data" id="theform">
         
        <div class="clear" style="height:5px"></div>
        <div class="bodycontent"> 
        <table class="box-vang" border="0" cellpadding="0" cellspacing="0" width="100%">
          <tbody><tr>
            <td class="t-l" width="8px"></td>
            <td class="t-c"></td>
            <td class="t-r" width="8px"></td>
          </tr>
          <tr class="light">
            <td class="c-l"></td>
            <td class="c-c"><table border="0" cellpadding="0" cellspacing="0" width="100%">
                <tbody><tr class="light">
                  <td class="title-red" colspan="2" align="left" id="canhan_tiemnang">&nbsp;Thêm mới cơ hội kinh doanh</td>
                   
                </tr>
               			   
                <tr><td class="title-red1" colspan="2">Thông tin cơ hội</td></tr>
				 <tr>
                 <td colspan="2">
                       <table width="100%">
					    	<tr class="light">
                  				<td width="50%">
         							<table width="100%" >
                    					<tr>
                                        	<td width="117" align="right">Tên cơ hội: </td>
                        					<td width="300">
                        						<input type="text" name="txtHoten" style="width:300px;"/> <span style="color:#F00"> *</span>
                        					</td>
                    					</tr>
                  						<tr>
                       						<td align="right">Khách hàng</td>
                      						<td>
                        	<input type="hidden" name="Kha_Id" id="Kha_Id">
                        	<input type="text" name="khachhang" style="width:300px;" id="khachhang" readonly="readonly"/>
                            <span style="color:#F00"> *</span>
                            <img src="../skins/images/btn_Lookup.png" onclick="popup('modules/customers/popupKH.php',800,500);" align="absmiddle">
                    <img width="16px" height="16px" align="absmiddle" onclick="document.getElementById(&#39;Kha_Id&#39;).value=&#39;&#39;;document.getElementById(&#39;khachhang&#39;).value=&#39;&#39;;" alt="del" src="../skins/images/Clear.gif">
                        </td>
                  						</tr>
                  						<tr> 
                  							<td align="right">Đầu mối liên lạc </td>
                                            <td>
                                        <div id="arr_dmll">
                                                <select style="width:300px" id="Dml_Id" name="Dml_Id"> 
                                                    <option>--Lựa chọn--</option>                                 
                                               </select>
                                       </div> 
                                            </td>
                  						</tr> 
                    				</table> 
                  				</td> 
                 				<td width="50%">
         							<table width="100%">                   
                     					<tr>
                       						<td align="right">Liên quan tới sản phẩm </td>
                      						<td>
                        <input type="hidden" name="sanphamsudung_id" id="dsid_nql2">
                        
                        <textarea cols="50" rows="3" readonly="readonly" style="width:300px;" name="sanphamsudung_name" id="ds_nql2">
                        </textarea>&nbsp;	
                       			
                        <span style="padding-left:5px;" class="openp_dialog3">
                        <img width="16px" height="16px" align="absmiddle" alt="pop" src="../skins/images/btn_Lookup.png">
                       
                        </span>
                         <img width="16px" height="16px" align="absmiddle" onclick="document.getElementById(&#39;dsid_nql2&#39;).value=&#39;&#39;;document.getElementById(&#39;ds_nql2&#39;).value=&#39;&#39;;" alt="del" src="../skins/images/Clear.gif">
											</td>
                       					</tr>            
                    				</table> 
                  				</td> 
                			</tr> 
				     	</table>  
                        <table width="100%"> 
                        	<tr class="light">
                            	<td align="right" width="13%">Mô tả cơ hội</td>
                                <td width="80%"> 
                                	<textarea style="width:840px; height:80px" name="mota"> </textarea>
                                </td>
                            </tr>
                        </table>        
			   		</td>
               	</tr>
                 <tr><td class="title-red1" colspan="2">Phân tích cơ hội</td></tr>
                  <tr class="light">
                  <td width="50%">
         			<table width="100%">
                    
                    <tr>
                      <td align="right" width="150">Doanh thu dự tính </td>
                      <td><input type="text" name="doanhthu" style="width:300px;"/>&nbsp;(VNĐ)</td></tr>
                  <tr>
                       <td align="right">Khả năng thành công</td>
                       <td><input type="text" name="thanhcong" style="width:300px;"/>&nbsp;(%)</td></tr>
                         <tr>
                       <td align="right">Đánh giá</td>
                       <td>
                       	<textarea style="width:300px" name="danhgia"> </textarea>
                       </td></tr>
                        <tr>
                       <td align="right">Ngày kết thúc</td>
                       <td><input type="text" name="ngayketthuc" style="width:300px;" id="ngayketthuc"/>
                       	<script type="text/javascript">
							$(function()
							{
								var arrayDayName=["CN","Hai","Ba","Tư","Năm","Sáu","Bảy"];
								var arrayMonthName=["Tháng 1","Tháng 2","Tháng 3","Tháng 4","Tháng 5","Tháng 6","Tháng 7","Tháng 8","Tháng 9","Tháng 10","Tháng 11","Tháng 12"];
								
								$('#ngayketthuc').datepicker({
									yearRange: 'c-12:c+8',
									changeMonth: true,
									changeYear: true,
									dateFormat: 'dd-mm-yy',
									showAnim: 'slideDown',
									monthNamesShort:arrayMonthName,
									dayNamesMin:arrayDayName
								});										
							});	
						</script>
                       </td></tr>          
                    </table> 
                  </td> 
                 <td width="50%">
         			<table width="100%">
                                 
                   <tr>
                      <td width="117" align="right">
                        Nguồn gốc cơ hội </td>
                      <td><select name="IDNguongoc" style="width:300px">
                <option value="" selected="selected">--Lựa chọn--</option>
                 <?php 
					$sqlstring="select services_type_name,services_type_id  from tb_services_type where phanloai_id=15 order by services_type_id asc";									
					$qr12=mysql_query($sqlstring);	
					while($row=mysql_fetch_array($qr12)) 
					{				
  					?>               
                 <option  value="<?=$row['services_type_id']?>"><?=$row['services_type_name']?></option>
                  <?php }?>            
                            </select></td>
                    </tr>
                   <tr><td align="right">Chiến dịch maketing:</td><td>           
                     <input type="hidden" name="marketing_id" id="idmkt">
            			
					<textarea cols="50" rows="2" readonly="readonly" style="width:300px;" id="tenmkt" name="txtmarketing" >
					</textarea>&nbsp;
					<img src="../skins/images/btn_Lookup.png" onclick="popup('modules/customers/popup_marketing.php',600,500);" align="absmiddle">
                    <img width="16px" height="16px" align="absmiddle" onclick="document.getElementById(&#39;idmkt&#39;).value=&#39;&#39;;document.getElementById(&#39;tenmkt&#39;).value=&#39;&#39;;" alt="del" src="../skins/images/Clear.gif">
					</td></tr>                       
                      <tr>
                        <td align="right">Đề xuất</td><td><textarea cols="56" rows="2" name="dexuat" style="width:300px;"></textarea></td>
                      </tr>
                    </table> 
                  </td> 
                </tr> 
            
<script type="text/javascript">
function LoadNguoiQL(str)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp == null)
{
alert ("Browser does not support HTTP Request");
return;
}

var url = "modules/customers/load_room.php";
url = url + "?room_id=" + str;

xmlhttp.onreadystatechange = stateChanged;
xmlhttp.open("GET", url, true);
xmlhttp.send(null);
}

function stateChanged()
{
if (xmlhttp.readyState == 4)
{
document.getElementById("nquanly").innerHTML = xmlhttp.responseText;

}
}

function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
return new XMLHttpRequest();
}
if (window.ActiveXObject)
{
// code for IE6, IE5
return new ActiveXObject("Microsoft.XMLHTTP");
}
return null;
}

</script>  
   
                 <tr><td class="title-red1" colspan="2">Thông tin quản lý</td></tr>
                <tr class="light">
                <td width="50%">
         			<table width="100%">
                    
                    <tr><td width="27%" align="right">Đơn vị quản lý: </td><td width="73%">
                                      
                <select class="box_input cbo" name="donviquanly"  style="width:300px" onchange="LoadNguoiQL(this.value)">
                        	<option value="">--Lựa chọn-- </option>
                            <?php 
						$sqlcode=mysql_query("select * from tb_room");
						while($rscode=mysql_fetch_array($sqlcode))
						{
							
					?>
                        	<option value="<?php echo $rscode['room_id'];?>"><?php echo $rscode['room_name'];?></option>
                              <?php }?>
                        </select>
                        <span style="color:#F00"> *</span>
                    
                    </td></tr>
                    <tr><td align="right">Người quản lý: </td><td>
                    <div id="nquanly">
                    			<select  id="nv_giao" style="width:300px">
                                <option value="">--Lựa chọn--</option>
								</select><span style="color:#F00"> *</span>
                        </div>
                        </td></tr>
                        <tr><td align="right">Người quản lý khác: </td><td>
                        <input type="hidden" name="Nguoi_Quan_Ly_Khac" id="dsid_nql">
                        <textarea cols="50" rows="3" readonly="readonly" style="width:300px;" name="nguoitheodoi" id="ds_nql" >
                        </textarea>&nbsp;					
                        <span style="padding-left:5px;" class="openp_dialog2">
                        <img width="16px" height="16px" align="absmiddle" alt="pop" src="../skins/images/btn_Lookup.png">
                        </span>
                         <img width="16px" height="16px" align="absmiddle" onclick="document.getElementById(&#39;dsid_nql&#39;).value=&#39;&#39;;document.getElementById(&#39;ds_nql&#39;).value=&#39;&#39;;" alt="del" src="../skins/images/Clear.gif">
					</td></tr>            
                    </table> 
                  </td> 
              <td width="50%">
                    <table width="100%">                   
                    <tr><td width="24%" align="right">Người tạo: </td><td width="76%">
                    	<input type="text" value="<?php echo $_SESSION['name'];?>" name="txtNguoitao" disabled="disabled" style="width:300px">
                     </td>
                    </tr>
                    <tr><td align="right">Ngày tạo: </td><td><input type="text" value="<?php echo date('d/m/Y h:i:s a');?>" name="txtNgaytao" disabled="disabled" style="width:300px">
                    </td>
                    </tr>   
                    <tr><td width="24%" align="right">Người cập nhật</td><td width="76%">
                    	<input type="text" value="<?php echo $_SESSION['name'];?>" name="txtNguoitao" disabled="disabled" style="width:300px">
                     </td>
                    </tr>              
                    <tr><td align="right">Ngày cập nhật: </td><td><input type="text" value="<?php echo date('d/m/Y h:i:s a');?>" disabled="disabled" name="txtNgaycapnhat" style="width:300px">
                    </td>
                    </tr>                   
                    </table> 
                  </td> 
                </tr> 
                 <tr><td class="title-red1" colspan="2">Đính kèm</td></tr>
                <tr  onmouseover="mouse_den(this)" onmouseout="mouse_di(this)">
                  <td >File đính kèm nếu có<br>
                    (*.gif, *.jpg, *.png, .doc, .pdf &lt; &nbsp;5000Kb)
			   <?php $soanh=1;?>
                 		<div id="myDiv" class="tdbg_2">
							<div style="float:left; width:100%; margin-top:5px;">
								<input type="hidden" id="userfile1" name="sanpham_hinhanh1"  value="<?php  echo $arr_hinhanh[0]?>"/>
								<?php if($arr_hinhanh[0]==""){$sanpham_hinhanh="../skins/images/photo.jpg";}else $sanpham_hinhanh = $arr_hinhanh[0];?>
								<img src="<?php  echo $sanpham_hinhanh?>" width="50" id="imgdef1" name="imgdef1" height="40" style="float:left; border:#CCC 1px solid" />
								
								<input type="button" name="button3" value="Up file đính kèm" onclick="JavaScript:window.open('core/Upfile.php?Dir=content&amp;form=userfile1&img=imgdef1','_upLoad' ,'height=220,width=450,resizable=no,scrollbars=yes')") />
								
								<input type="hidden" value="<?php echo $soanh;?>" name="hdnsoanh" id="theValue" />
								<a href="javascript:;" onclick="addElement();">Thêm file đính kèm</a>
							</div>
							<?php
								for($i=2; $i<=$soanh;$i++){
								$hinhanh = $arr_hinhanh[$i-1];
							?>
								<div id="my<?php echo $i;?>Div" style="float:left; width:100%; margin-top:5px;">
									<input type="hidden" id="userfile<?php echo $i;?>" name="sanpham_hinhanh<?php echo $i;?>"  value="<?php  echo $hinhanh?>"/>
									<img src="<?php echo $hinhanh?>" width="50" id="imgdef<?php echo $i;?>" name="imgdef<?php echo $i;?>" height="40" style="float:left; border:#CCC 1px solid" />
								  
								   <input type="button" name="button3" value="Up file đính kèm" onclick="JavaScript:window.open('core/Upfile.php?Dir=content&amp;form=userfile<?php echo $i;?>&img=imgdef<?php echo $i;?>','_upLoad' ,'height=220,width=450,resizable=no,scrollbars=yes')") />
								 
								   <a href="javascript:;" onclick="removeElement('my<?php echo $i;?>Div');">Delete</a>
								</div>
							<?php
								}
							?>
                            </div>
						    </td>
                </tr>
          
                <tr><td height="10px"></td></tr>
                <tr><td colspan="2" style="padding-left:150px;"><input class="buttonnew" name="submit" id="submit" value="Lưu lại" type="submit">&nbsp;<input class="buttonnew" name="submit" id="submit" value="Hủy bỏ" type="submit"></td></tr>
                
              </tbody> </table></td>
            <td class="c-r"></td>
          </tr>
          <tr>
            <td class="b-l"></td>
            <td class="b-c"></td>
            <td class="b-r"></td>
          </tr>
        </tbody></table>
        
</form>
	  
	  
	  
<script>
	function call_list_user(url){
		var str = "";
		var str_id="";
		$("#nguoi_qlkhac input[type='checkbox']").each(function(){
			if($(this).is(':checked'))
			{
				if($(this).attr('name')!='DonVi'){
					str+= $(this).next().text() +', ';
					str_id+= $(this).val() +',';
				}
					
			}	
		});
				
		document.getElementById('ds_nql').value=str;	
		document.getElementById('dsid_nql').value=str_id;
	
	}
	
	
function close_popup_nqlk(){
    $("#").dialog("close");
}

	$(document).ready(function(){
	$(".openp_dialog2").click(function(){
        $("#dialog2").dialog("open");dialog2
    });
	$("#dialog2").dialog({
        autoOpen: false,
        height: 500,
        width: 500,
        modal: true,
		resizable: false,
		buttons: {
				'Hủy bỏ': function() {
					
					$( this ).dialog( "close" );
				},
				'Chọn': function() {
					call_list_user('');
					$( this ).dialog( "close" );
				}
				
				
			}
    });
	
});
</script>

<div style="display: none; position: absolute; overflow: hidden; z-index: 1002; outline: 0px; height: auto; width: 500px; top: 82.5px; left: 432px;" class="ui-dialog ui-widget ui-widget-content ui-corner-all  ui-draggable" tabindex="-1" role="dialog" aria-labelledby="ui-dialog-title-dialog2">
	<div class="ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix" unselectable="on">
    	<span>Chọn đơn vị hoặc người dùng</span>
        <span class="ui-icon ui-icon-closethick" unselectable="on">close</span></div>
		<div id="dialog2" style="padding-left: 0px; height: 436px; min-height: 86px; width: auto;" class="ui-dialog-content ui-widget-content">	

<form id="frmNql" name="frmNql">
	<div id="nguoi_qlkhac" style="height:auto;">
		<div style="width:100%; height:auto;margin-left:20px;">
          <?php 
		
			$sql=mysql_query("select * from tb_room");
			$i=0;
		?>
        <?php while($row=mysql_fetch_array($sql))
			{$i=$i+1;
			
				$room_id=$row['room_id'];
			?>
			<div style="float:left; width:50%;">
                <div style="color: #0070BA;width:100%;float:left;text-align:left;">
                    <input type="checkbox" onclick="selectReverse('frmNql','nql_<?php echo $i;?>')" style="width:auto;" name="DonVi" class="item"><b>
					<?php echo $row['room_name']?></b>
                </div>
				<div style="color: #0070BA;width:100%;float:left;margin-left:35px;">
				 <?php 
				$sql2=mysql_query("select account_id,room_id,account_name from tb_account_admin where room_id='$room_id'");
				?>
                <?php while($rs=mysql_fetch_array($sql2)){?>			  
                     <span class="nql_<?php echo $i;?>" style="float:left;text-align:left;width:100%;">
                        <input id="nql_<?php echo $i;?>_0" type="checkbox" style="width:auto;" name="arr_Cus_Id[]" value="<?php echo $rs['account_id'];?>" class="item">&nbsp;<b><?php echo $rs['account_name'];?></b>
                     </span>
                  <?php }?> 
                     
				</div>
              
		   </div>
		    <?php }?>
	</div>
    
	</form>
	</div>	</div>
	
	
<!--end popup-->   



<script>
	function call_list_user2(url){
		var str2 = "";
		var str_id2="";
		$("#nguoi_qlkhac2 input[type='checkbox']").each(function(){
			if($(this).is(':checked'))
			{
				if($(this).attr('name')!='DonVi2'){
					str2+= $(this).next().text() +', ';
					str_id2+= $(this).val() +',';
				}
					
			}	
		});
				
		document.getElementById('ds_nql2').value=str2;	
		document.getElementById('dsid_nql2').value=str_id2;	
	}	
	
function close_popup_nqlk2(){
    $("#").dialog("close");
}

	$(document).ready(function(){
	$(".openp_dialog3").click(function(){
        $("#dialog3").dialog("open");
    });
	$("#dialog3").dialog({
        autoOpen: false,
        height: 500,
        width: 500,
        modal: true,
		resizable: false,
		buttons: {
				'Hủy bỏ': function() {
					
					$( this ).dialog( "close" );
				},
				'Chọn': function() {
					call_list_user2('');
					$( this ).dialog( "close" );
				}
				
				
			}
    });
	
});
</script>

    	<span>Chọn đơn vị hoặc người dùng</span>
        <span class="ui-icon ui-icon-closethick" unselectable="on">close</span>
        <div id="dialog3" style="padding-left: 0px; height: 436px; min-height: 86px; width: auto;" class="ui-dialog-content ui-widget-content">	
          
  <form id="frmNq2" name="frmNq2">
	<div id="nguoi_qlkhac2" style="height:auto;">
		<div style="width:100%; height:auto;margin-left:20px;">
       
       
         <?php 
		
			$sql=mysql_query("select services_type_name,services_type_id,services_parrent_id  from tb_services_type where phanloai_id=18 order by services_type_id asc");
			$i=60;
		?>
        <?php while($row=mysql_fetch_array($sql))
			{$i=$i+1;
			
				$parrent=$row['services_type_id'];
			?>
			<div style="float:left; width:50%;">
                <div style="color: #0070BA;width:100%;float:left;text-align:left;">
                    <input type="checkbox" onclick="selectReverse('frmNq2','nql1_<? echo $i;?>')" style="width:auto;" name="DonVi2" value="" class="item"><b>
					<?php echo $row['services_type_name']?>                    
                    </b>
                </div>
				
                <div style="color: #0070BA;width:100%;float:left;margin-left:35px;">
				 <?php 
				$sql3=mysql_query("select * from tb_product where services_type_id='$parrent'");
				?>
                <?php while($rsw=mysql_fetch_array($sql3)){?>			  
                     <span class="nql1_<? echo $i;?>" style="float:left;text-align:left;width:100%;">
                        <input id="nql1_<? echo $i;?>_0" type="checkbox" style="width:auto;"  value="<?php echo $rsw['IDproduct'];?>" class="item">&nbsp;<b><?php echo $rsw['Namepro'];?></b>
                       
                     </span>
                  <?php }?> 
				</div>
              
		   </div>
		    <?php }?>
          
		   
	</div>
    
	</form>
</div>
